package o;

import android.os.Handler;
import androidx.annotation.CallSuper;
import androidx.annotation.Nullable;
import java.io.IOException;
import java.util.HashMap;
import o.ail.e;
import o.aim.a;
import o.aim.c;

public abstract class ahv<T> extends ahy {
    @Nullable
    private alx ˋ;
    private final HashMap<T, b> ˎ = new HashMap();
    @Nullable
    private Handler ॱ;

    static final class b {
        public final ail ˎ;
        public final aim ˏ;
        public final c ॱ;

        public b(aim o_aim, c cVar, ail o_ail) {
            this.ˏ = o_aim;
            this.ॱ = cVar;
            this.ˎ = o_ail;
        }
    }

    final class d implements ail {
        private final T ˊ;
        private ail.c ˎ;
        final /* synthetic */ ahv ˏ;

        public d(ahv o_ahv, T t) {
            this.ˏ = o_ahv;
            this.ˎ = o_ahv.ˏ(null);
            this.ˊ = t;
        }

        public void ˊ(int i, a aVar) {
            if (ॱ(i, aVar)) {
                this.ˎ.ॱ();
            }
        }

        public void ˏ(int i, a aVar) {
            if (ॱ(i, aVar)) {
                this.ˎ.ˏ();
            }
        }

        public void ˏ(int i, @Nullable a aVar, ail.a aVar2, e eVar) {
            if (ॱ(i, aVar)) {
                this.ˎ.ˏ(aVar2, ॱ(eVar));
            }
        }

        public void ˎ(int i, @Nullable a aVar, ail.a aVar2, e eVar) {
            if (ॱ(i, aVar)) {
                this.ˎ.ˋ(aVar2, ॱ(eVar));
            }
        }

        public void ॱ(int i, @Nullable a aVar, ail.a aVar2, e eVar) {
            if (ॱ(i, aVar)) {
                this.ˎ.ˊ(aVar2, ॱ(eVar));
            }
        }

        public void ˊ(int i, @Nullable a aVar, ail.a aVar2, e eVar, IOException iOException, boolean z) {
            if (ॱ(i, aVar)) {
                this.ˎ.ˏ(aVar2, ॱ(eVar), iOException, z);
            }
        }

        public void ˎ(int i, a aVar) {
            if (ॱ(i, aVar)) {
                this.ˎ.ˎ();
            }
        }

        public void ˊ(int i, @Nullable a aVar, e eVar) {
            if (ॱ(i, aVar)) {
                this.ˎ.ॱ(ॱ(eVar));
            }
        }

        private boolean ॱ(int i, @Nullable a aVar) {
            a aVar2 = null;
            if (aVar != null) {
                aVar2 = this.ˏ.ˊ(this.ˊ, aVar);
                if (aVar2 == null) {
                    return false;
                }
            }
            int ˊ = this.ˏ.ˊ(this.ˊ, i);
            if (!(this.ˎ.ˏ == ˊ && anr.ˎ(this.ˎ.ˋ, aVar2))) {
                this.ˎ = this.ˏ.ˊ(ˊ, aVar2, 0);
            }
            return true;
        }

        private e ॱ(e eVar) {
            long ˎ = this.ˏ.ˎ(this.ˊ, eVar.ʼ);
            long ˎ2 = this.ˏ.ˎ(this.ˊ, eVar.ʽ);
            return (ˎ == eVar.ʼ && ˎ2 == eVar.ʽ) ? eVar : new e(eVar.ˋ, eVar.ॱ, eVar.ˊ, eVar.ˎ, eVar.ˏ, ˎ, ˎ2);
        }
    }

    protected abstract void ˋ(T t, aim o_aim, abr o_abr, @Nullable Object obj);

    protected ahv() {
    }

    @CallSuper
    public void ॱ(@Nullable alx o_alx) {
        this.ˋ = o_alx;
        this.ॱ = new Handler();
    }

    @CallSuper
    public void ॱ() throws IOException {
        for (b bVar : this.ˎ.values()) {
            bVar.ˏ.ॱ();
        }
    }

    @CallSuper
    public void ˎ() {
        for (b bVar : this.ˎ.values()) {
            bVar.ˏ.ˎ(bVar.ॱ);
            bVar.ˏ.ˏ(bVar.ˎ);
        }
        this.ˎ.clear();
    }

    protected final void ˊ(T t, aim o_aim) {
        amm.ˊ(!this.ˎ.containsKey(t));
        c o_aid = new aid(this, t);
        ail dVar = new d(this, t);
        this.ˎ.put(t, new b(o_aim, o_aid, dVar));
        o_aim.ˏ((Handler) amm.ॱ(this.ॱ), dVar);
        o_aim.ॱ(o_aid, this.ˋ);
    }

    private /* synthetic */ void ॱ(Object obj, aim o_aim, abr o_abr, Object obj2) {
        ˋ(obj, o_aim, o_abr, obj2);
    }

    protected int ˊ(T t, int i) {
        return i;
    }

    @Nullable
    protected a ˊ(T t, a aVar) {
        return aVar;
    }

    protected long ˎ(@Nullable T t, long j) {
        return j;
    }
}
